﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

using DevExpress.Xpf.Core;

namespace BlueMonkey.View
{
    /// <summary>
    /// Interaction logic for XTabContainer.xaml
    /// </summary>
    public partial class XTabContainer : UserControl
    {
        public XTabContainer()
        {
            InitializeComponent();
        }

        public bool AddTab(DXTabItem tabItem)
        {
            try
            {
                dXTabControl1.Items.Add(tabItem);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public DXTabItem XTabItem(string name,string header, object content)
        {
            DXTabItem item = new DXTabItem();
            item.Name = name;
            item.Header = header;
            item.Content = content;
            item.AllowHide = DevExpress.Utils.DefaultBoolean.True;

            return item;
        }

        public DXTabItem XVideoTab(BlueCore.MediaObject path)
        {
            DXTabItem item = new DXTabItem();
            item.AllowHide = DevExpress.Utils.DefaultBoolean.True;
            item.Header = "header";
            item.IsVisibleChanged += new DependencyPropertyChangedEventHandler(Video_IsVisibleChanged);

            VideoPlayer player = new VideoPlayer();
            player.Media = path;

            item.Content = player;
            return item;
        }

        void Video_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            DXTabItem item = sender as DXTabItem;
            VideoPlayer player = item.Content as VideoPlayer;

            if (item.CloseButton != null)
            {
                player.Stop();
            }
        }
    }
}
